﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace Fx.Mvc.Helpers
{
    public static class ActiveMenuHelper
    {
        /// <summary>
        /// Marks the tag li with class = 'active' if the request controller is as same as defined controller
        /// </summary>
        /// <param name="helper">A Html helper</param>
        /// <param name="controller">The name of controller in menu we need it being active</param>
        /// <param name="className">Name of class will be used for active menu.</param>
        public static IHtmlString Active(this HtmlHelper helper, string controller, string className = "active")
        {
            var requestController = helper.ViewContext.RouteData.GetRequiredString("controller");
            if (requestController != null)
                requestController = requestController.ToLower().Trim();
            if (controller != null)
                controller = controller.ToLower().Trim();
            if (requestController == controller)
                return new HtmlString("class='" + className + "'");
            return null;
        }
    }
}
